<template>
<h2>计算器练习</h2>
  <input type="text" v-model="n1">
  <input type="text" v-model="n2">
  <input type="button" value="加" @click="f('+')">
  <input type="button" value="减" @click="f('-')">
  <input type="button" value="乘" @click="f('*')">
  <input type="button" value="除" @click="f('/')">
  <h3>结果:{{result}}</h3>
</template>

<script setup>
  import {ref} from "vue";

  const n1 = ref('');
  const n2 = ref('');
  const result = ref('');
  const f = (x)=>{
    //  "2+5"   eval(字符串)  此方法可以将字符串 以JS代码的形式运行 并得到结果
    result.value = eval(n1.value+x+n2.value);
  }
</script>

<style scoped>

</style>